<template>
    <div>
        <h1>Count组件求和值为：{{sum}}</h1>
        <input type="text" v-model="name">
        <button @click="add">添加</button>
        <ul>
            <li v-for="p in personList" :key="p.id">{{ p.name }}</li>
        </ul>  
    </div>
</template>

<script>
import { nanoid } from 'nanoid'
export default {
    name:'Person',
    data() {
      return {
        name:''
      }
    },
    computed:{
        sum(){
            return this.$store.state.countAbout.sum
        },
        personList(){
            return this.$store.state.personAbout.personList
        }
    },
    methods: {
        add(){
            const pObj = {id:nanoid(),name:this.name}
            this.$store.commit('personAbout/ADD_PERSON',pObj)
            this.name = ''
        }
    }
}
</script>

<style scoped>
</style>